package com.atjava.nebula.core.dao.ibatis.script;

/**
 * 组合sql语句
 * @author kyo
 *
 */
public class MsSQL2KScript implements SqlScript {

	/**
	 * 用值替换PreparedStatement 语句里的?号
	 */
	public String replaceParameter(String sql, Object ...objects) {
		for (int i = 0; i < objects.length; i++) {
			sql = sql.replaceFirst("\\?", getString(objects[i]));
		}
		return sql;
	}

	/**
	 * 包装对象的值,变成SQL语句
	 * @param object
	 * @return
	 */
	private String getString(Object object) {
		if (object instanceof String||object instanceof Character) {
			return "'" + object + "'";
		} else {
			return object.toString();
		}
	}

}
